<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<% 
String path = request.getContextPath(); 
// 获得项目完全路径（假设你的项目叫MyApp，那么获得到的地址就是 http://localhost:8080/MyApp/）: 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<!DOCTYPE html>
<html>
<head>
<base href=" <%=basePath%>"> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="后台书籍管理">
<meta name="author" content="xwj">
<title>书籍管理</title>
<link href="bootstrap/bootstrap.css" rel="stylesheet">
<!--external css-->
<link href="css/admin_css/assets/font-awesome/css/font-awesome.css"
	rel="stylesheet" />
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/css/zabuto_calendar.css">
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/js/gritter/css/jquery.gritter.css" />
<link rel="stylesheet" type="text/css"
	href="css/admin_css/assets/lineicons/style.css">

<!--  Custom styles for this template -->
<link href="css/admin_css/assets/css/style.css" rel="stylesheet">
<link href="css/admin_css/assets/css/style-responsive.css"
	rel="stylesheet">
<style>
#add_books{
background:#FFF;
width:80%;
padding-top:2%;
padding-left:5%;
margin-left:10%;
}
#imgPreview { float: left; border: none; }
 #imgPreview img { margin-right: 10px; width: 100px; } 
 .upload-img { display: block; float: left; width: 80px; height: 80px; overflow: hidden; position: relative; background: url("images/public/defaul.png") no-repeat 0; background-size: contain; }  
.upload-img input { height: 50px; opacity: 0; filter: alpha(opacity=0); position: absolute; top: 0; right: 0; }

</style>
<script src="jquery/jquery-2.2.4.min.js"></script>
<script src="bootstrap/bootstrap.min.js"></script>
	<!-- js placed at the end of the document so the pages load faster -->
 <script class="include" type="text/javascript"
		src="css/admin_css/assets/js/jquery.dcjqaccordion.2.7.js"></script> 
	<script src="css/admin_css/assets/js/jquery.scrollTo.min.js"></script>
	<script src="css/admin_css/assets/js/common-scripts.js"></script> 
	<!-- 分页工具 -->
<script type="text/javascript" src="jsutil/pagetool.js"></script>
<!-- 时间处理工具 -->
<script type="text/javascript" src="jsutil/timeutil.js"></script>
<!-- 表单验证 -->
<script
	src="bootstrap/bootstrapvalidator/js/bootstrapValidator.min.js"></script>
<script>


var bid;				//图书id
$(function(){
	getCategory();
	var h=window.location.href;
	var a=h.split("?id=");
	bid=a[1];
	getOneBook();
	//类别添加表单验证
	//类别添加表单验证
	$("#update_form").bootstrapValidator({
		message : 'This value is not valid',
		feedbackIcons : {/*输入框不同状态，显示图片的样式*/
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {/*验证*/
			
			bname : {
				message : 'The cdesc is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '书名不能为空'
					},
					stringLength : {/*长度提示*/
						max : 16,
						message : '书名的长度必须小于16位'
					}
				}
			},
			bauthor:{
				message : 'The bauthor is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '作者名不能为空'
					},
					stringLength : {/*长度提示*/
						max : 16,
						message : '作者的长度必须小于16位'
					}
				}
			},
			cid:{
				message : 'The cid is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '类别不能为空'
					},
					regexp: {
	                 	regexp: /^[1-9]/,
	                 	message: '类别不能为空' 
	                 }
				}
			},
			bpress:{
				message : 'The bpress is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '出版社不能为空'
					},
					stringLength : {/*长度提示*/
						max : 16,
						message : '出版社的长度必须小于16位'
					}
				}
			},
			borgprice:{
				message : 'The borgprice is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '原价不能为空'
					},
					 regexp: {
		                 	regexp: /^([1-9][0-9]*)+(.[0-9]{1,2})?$/,
		                 	message: '必须是整数或者两位小数' 
		                 },
					stringLength : {/*长度提示*/
						max : 16,
						message : '原价的长度必须小于16位'
					}
				}
			},
			bprice:{
				message : 'The borgprice is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '现价不能为空'
					},
					 regexp: {
		                 	regexp: /^([1-9][0-9]*)+(.[0-9]{1,2})?$/,
		                 	message: '必须是整数或者两位小数' 
		                 },
					stringLength : {/*长度提示*/
						max : 16,
						message : '现价的长度必须小于16位'
					}
				}
			},
			bnumber:{
				message : 'The bnumber is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '数量不能为空'
					},
					 regexp: {
		                 	regexp: /^[1-9]\d*$/,
		                 	message: '必须是整数' 
		                 },
					stringLength : {/*长度提示*/
						max : 6,
						message : '数量的长度必须小于6位'
					}
				}
			},
			bdesc : {
				message : 'The cdesc is not valid',
				validators : {
					notEmpty : {/*非空提示*/
						message : '描述不能为空'
					},
					stringLength : {/*长度提示*/
						min :4,
						max : 100,
						message : '描述的长度必须4到100之间'
					}
				}
			}
		}
	});
});


//获得单个书籍
function getOneBook(){
 	$.ajax({
			url : "booksMsg/getOneBookById.do", // 请求地址
			type : "POST", // 请求类型
			async : "true", // 是否异步方式
			data : {"bid":bid},
			dataType : "json", // 返回数据格式
			success : function(data) {
				if (data.res>0) {
					$.each(data.list,function(index, element) {
						var pdate=Todate(element.bpressdate); 
						$('#bpic').attr('src', element.bpicurl); 
						$("#up_bnum").val(element.bnum);
						$("#up_bname").val(element.bname);
						$("#up_bauthor").val(element.bauthor);
						$("#theid").val(element.category.cid);
						$("#up_bflag").val(element.bflag);
						$("#up_bpress").val(element.bpress);
						$("#up_bpressdate").val(pdate);
						$("#up_borgprice").val(element.borgprice);
						$("#up_bprice").val(element.bprice);
						$("#up_bnumber").val(element.bnumber);
						$("#up_bsalenum").val(element.bsalenum);
						$("#up_bdesc").val(element.bdesc);
			    		
					});
					
						
	           
				}
			}
		});
}

//修改书籍信息
function changeBookInfo() {
	var bv = $("#update_form").data('bootstrapValidator');
	bv.validate();
	if (!bv.isValid()) {
		return;
	}
	if (!confirm("确认要修改吗?")) {
		return;
	}
	var bname=$("#up_bname").val();
	var bauthor=$("#up_bauthor").val();
	var tid=$("#theid").val();
	var bflag=$("#up_bflag").val();
	var bpress=$("#up_bpress").val();
	var bpdate=$("#up_bpressdate").val();
	var boprice=$("#up_borgprice").val();
	var bprice=$("#up_bprice").val();
	var bnumber=$("#up_bnumber").val();
	var bdesc=$("#up_bdesc").val();

	$.ajax({
		url : "booksMsg/changeBookInfo.do",
		type : 'POST',
		async : "true",
		data : {"bid":bid,
				"bname":bname,
				"bauthor":bauthor,
				"tid":tid,
				"bflag":bflag,
				"bpress":bpress,
				"bpressdate":bpdate,
				"boprice":boprice,
				"bprice":bprice,
				"bnumber":bnumber,
				"bdesc":bdesc
			},
		dataType : 'json',
		success : function(data) {
			if (data.res> 0) {
				alert("修改成功");
				window.location.href="admin/book_edit.jsp?id="+bid;
			} else {
				alert("修改失败！");
				
			}
		}
	});
	
}
//重置表单
function resForm(){
	if (!confirm("确认要重置吗?")) {
		return;
	}
	alert(bid);
	window.location.href="admin/book_edit.jsp?id="+bid;

}
//获取类型
function getCategory(){
	$.post("categoryMsg/getAllCategory.do",{},
			function(data){
				var theme=$("select[name='cid']");
				theme.append("<option value='-1' selected>请选择</option>");
				$.each(data.list,function(index,element){
					
					theme.append("<option value='"+element.cid+"'>"+element.cname+"</option>");
				});
			},"json"); 
	
	}

</script>
	
</head>
<body>


	<section id="container">

		<%@include file="header.jsp" %>

		<!--sidebar start-->
		<aside>
			<div id="sidebar" class="nav-collapse ">
				<!-- sidebar menu start-->
				<ul class="sidebar-menu" id="nav-accordion">

					<p class="centered">
						<a href="admin/adminmag.jsp"><img
							src="images/admin7.png" class="img-circle"
							width="60"></a>
					</p>
					<h5 class="centered">${admin.aname}</h5>

					<li class="mt"><a href="admin/index.jsp"> <i
							class="fa fa-bar-chart-o"></i> <span>销售统计</span>
					</a></li>

					<li class="sub-menu"><a class="active" href="javascript:;">
							<i class="fa fa-book"></i> <span>书籍</span>
					</a>
						<ul class="sub">
							<li class="active"><a href="admin/bookmag.jsp">书籍管理</a></li>
							<li ><a href="admin/categorymag.jsp">类别管理</a></li>

						</ul></li>

					<li class="sub-menu"><a href="javascript:;"> <i
							class="fa fa-users"></i> <span>账户</span>
					</a>
						<ul class="sub">
							<li><a href="admin/usermag.jsp">用户管理</a></li>
							<li><a href="admin/adminmag.jsp">管理员管理</a></li>

						</ul></li>
					<li class="sub-menu"><a href="javascript:;"> <i
							class="fa fa-user"></i> <span>会员</span>
					</a>
						<ul class="sub">
							<li><a href="admin/membermag.jsp">会员折扣管理</a></li>

						</ul></li>
					<li class="sub-menu"><a href="javascript:;"> <i
							class="fa fa-shopping-cart"></i> <span>订单</span>
					</a>
						<ul class="sub">
							<li><a href="admin/ordermag.jsp">订单管理</a></li>
						</ul></li>

				</ul>
				<!-- sidebar menu end-->
			</div>
		</aside>
		<!-- **********************************************************************************************************************************************************
     以上是不变的内容--包括上边header和左边aside33###以下是变化的内容
      *********************************************************************************************************************************************************** -->

		<!--main content start-->
		<section id="main-content">

			<section class="wrapper">
				<div class="row" id="add_books">
					<h3>
					<i class="fa fa-angle-right"></i> 书籍详细信息
					</h3>
						<div class="modal-body">
						<form class="form-horizontal" role="form">
						<div class="form-group">
							<label for="add_bpicurl" class="col-sm-1 control-label">图片</label>
							<div class="col-sm-8">
							<div id="imgPreview"></div>
							 <span class="upload-img">
							<img src='' id="bpic" width="100"/>
							 </span>
							</div>
							</div>
						</form>
					<form class="form-horizontal"  id="update_form">
					
						<div class="form-group">
							<label for="add_bnum" class="col-sm-1 control-label">编号</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bnum" name="bnum"
									readonly placeholder="请输入书的编号">
							</div>
						</div>
							<div class="form-group">
							<label for="add_bname" class="col-sm-1 control-label">书名</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bname" name="bname"
									placeholder="请输入书的名字">
							</div>
						</div>
						<div class="form-group">
							<label for="add_bauthor" class="col-sm-1 control-label">作者</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bauthor" name="bauthor"
									placeholder="请输入书的作者">
							</div>
						</div>
							<div class="form-group">
							<label for="theid" class="col-sm-1 control-label">类别</label>
							<div class="col-sm-8">
							<select id="theid"  class="form-control" name="cid">
							</select>
							</div>
							</div>
							<div class="form-group">
							<label for="up_bflag" class="col-sm-1 control-label">是否上架</label>
							<div class="col-sm-8">
							<select  class="form-control" id="up_bflag">
							<option  value='0'>否</option>
							<option value='1'>是</option>
							</select>
							</div>
							</div>
						
							<div class="form-group">
							<label for="add_bauthor" class="col-sm-1 control-label">出版社</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bpress" name="bpress"
									placeholder="请输入书的出版社">
							</div>
						</div>
							<div class="form-group">
							<label for="bpressdate1" class="col-sm-1 control-label">出版时间</label>
							<div class="col-sm-8">
								<input type="date" class="form-control" id="up_bpressdate" name="bpressdate"
									placeholder="请输入书的出版时间">
							</div>
						</div>
						<div class="form-group">
							<label for="borgprice1" class="col-sm-1 control-label">原价</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_borgprice" name="borgprice"
									placeholder="请输入书的原价">
							</div>
						</div>
						<div class="form-group">
							<label for="add_bauthor" class="col-sm-1 control-label">现价</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bprice" name="bprice"
									placeholder="请输入书的现价">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-1 control-label">库存</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bnumber" name="bnumber"
									placeholder="请输入书的库存量">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-1 control-label">销售量</label>
							<div class="col-sm-8">
								<input type="text" class="form-control" id="up_bsalenum" 
								readonly placeholder="销售">
							</div>
						</div>
					
							<div class="form-group">
							<label for="add_bauthor" class="col-sm-1 control-label">描述</label>
							<div class="col-sm-8">
								<textarea class="form-control" rows="3" id="up_bdesc"
									name="bdesc" placeholder="请输入书的描述"></textarea>
							</div>
						</div>
							<div class="form-group">
							
							</div>
					
					</form>
					
								
				</div>
				<div class="col-sm-4"></div>
				<div class="col-sm-8">
					<button class="btn btn-primary" onclick="changeBookInfo()">修改</button>
					<button class="btn btn-warning" onclick="resForm()">重置</button>
				</div>
			</div>
			
			</section>

		</section>
		<!-- /MAIN CONTENT -->

		<!--main content end-->
		<!--footer start-->
		<%@include file="footer.jsp"%>
		<!--footer end-->

	</section>



</body>
</html>